// react-query
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
// react
import { Suspense } from 'react';
import ReactDOM from 'react-dom/client';
// react helmet
import { HelmetProvider } from 'react-helmet-async';
// eslint-disable-next-line import/no-unresolved
import 'virtual:svg-icons-register';
// import microApp from '@micro-zoe/micro-app'
import App from '@/App';
//初始化micro-app
// microApp.start({
//   iframeSrc: import.meta.env.MODE === 'development' ? '/empty.html' : '/integration/empty.html'
// })
import '@/utils/microApp/index'
// import worker from './_mock';
// i18n
// tailwind css
import './theme/index.scss';

// 创建一个 client
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: 0, // 失败重试次数
      gcTime: 300_000, // 缓存有效期 5m
      staleTime: 10_1000, // 数据变得 "陈旧"（stale）的时间 10s
      refetchOnWindowFocus: false, // 禁止窗口聚焦时重新获取数据
      refetchOnReconnect: false, // 禁止重新连接时重新获取数据
      refetchOnMount: false, // 禁止组件挂载时重新获取数据
    },
  },
});



// 👇 将渲染操作放入 mount 函数 -- 必填
export function mount () {
  const root = ReactDOM.createRoot(document.getElementById('root'));

  root.render(
    <HelmetProvider>
      <QueryClientProvider client={queryClient}>
        <ReactQueryDevtools initialIsOpen={false} />
        <Suspense>
          <App />
        </Suspense>
      </QueryClientProvider>
    </HelmetProvider>,
  );
}

// 👇 将卸载操作放入 unmount 函数 -- 必填
export function unmount () {
  const root = ReactDOM.createRoot(document.getElementById('root'));
  root.unmount()
}
window.mount = mount
window.unmount = unmount
// 微前端环境下，注册mount和unmount方法
if (window.__MFE_ENV__) {
  window[`micro-app-${window.MFE.name}`] = { mount, unmount }
} else {
  // 非微前端环境直接渲染
  mount()
}